//
//  YHCardStyleVC.m
//  LyhToolsTest
//
//  Created by 李彦宏 on 2019/6/30.
//  Copyright © 2019 LYH.com. All rights reserved.
//

#import "YHCardStyleVC.h"

@interface YHCardStyleVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView *collectionview;
@property (nonatomic, strong) NSArray *colorArray;
@end

@implementation YHCardStyleVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self collectionview];
    [self initnava];
}
-(void)initnava
{
    WeakSelf;
    wself.ts_navgationBar = [TSNavigationBar navWithTitle:@"卡片效果" backAction:^{
        [self.navigationController popViewControllerAnimated:YES];
    }];
}
#pragma -mark ---------------------collectionView的代理和数据源方法---------------------------------
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YHImageCell *cell = [YHImageCell codeCell:collectionView cellForItemAtIndexPath:indexPath];
    
    cell.imageViewitem.backgroundColor = self.colorArray[indexPath.row];
    cell.imageViewitem.cornerRadius = 10;
    return cell;
    
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return -10;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

//懒加载collectionview
- (UICollectionView *)collectionview
{
    if (!_collectionview) {
        UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection=UICollectionViewScrollDirectionVertical;//竖直滚动
        layout.itemSize=CGSizeMake(kScreenWidth-20,150);
        layout.minimumInteritemSpacing=0;
        layout.sectionInset=UIEdgeInsetsMake(10, 10, 0, 10);
        
        _collectionview=[[UICollectionView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, kScreenWidth, kScreenHeigth-SafeAreaTopHeight) collectionViewLayout:layout];
        _collectionview.dataSource=self;
        _collectionview.delegate=self;
        _collectionview.backgroundColor=[UIColor whiteColor];
        //支持分页
        _collectionview.pagingEnabled=NO;
        _collectionview.scrollEnabled=YES;
        _collectionview.alwaysBounceVertical = YES;//数据少时也能滚动
        [self.view addSubview:_collectionview];
    }
    return _collectionview;
}
- (NSArray *)colorArray
{
    if (!_colorArray) {
        _colorArray = @[[UIColor redColor],[UIColor orangeColor],[UIColor blueColor],HexColor(@"232211"),ThemeColor,[UIColor yellowColor]];
    }
    return _colorArray;
}
@end
